#![no_std]

pub extern crate alloc;
mod mutex;

// 提供给内核使用的互斥锁
// 需要外部提供一些函数
pub use mutex::KMutex;
pub use mutex::KMutexGuard;
pub use mutex::TMutex;
use core::ops::{Add, Sub};

// 调度锁
pub struct SchedulerLockNested(KMutex<u32>);

impl SchedulerLockNested {
    pub fn scheduler_lock(&self) {
        let mut i = self.0.lock();
        *i = i.add(1);
    }

    pub fn scheduler_unlock(&self) {
        let mut i = self.0.lock();
        *i = i.sub(1);
    }

    pub fn scheduler_able(&self) -> bool {
        let i = self.0.lock();
        if *i == 0 {
            true
        } else {
            false
        }

    }
}

pub static SCHEDULER_LOCK_NESTED: SchedulerLockNested = SchedulerLockNested (KMutex::new(0));
